/*
 * Copyright 2010 Gal Dolber.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.unnison.demo.client.complexplace;

import com.google.inject.Inject;

import com.unnison.demo.client.complexplace.ComplexPlacePresenter;
import com.unnison.demo.client.complexplace.ComplexPlacePresenter.ComplexPlaceBinder;
import com.unnison.demo.client.main.MainPresenter;
import com.unnison.framework.junit.GuitTest;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

public class TestComplexPlacePresenter extends GuitTest {

    @Inject
    ComplexPlacePresenter presenter;

    @Override
    protected void configure() {
        mock(ComplexPlaceBinder.class);
        mock(MainPresenter.class);
    }

    @Before
    public void initialize() {
        presenter.go(null);
    }
    

    @Test
    public void testPojoEquals() {
        Assert.assertEquals(presenter.checkbox, presenter.checkbox);
    }

    @Test
    public void testCheckbox() {
        Assert.assertEquals(true, presenter.data.isEnabled());
        presenter.checkbox.setValue(false);
        presenter.checkboxOrTextboxChange(presenter.checkbox);
        Assert.assertEquals(false, presenter.data.isEnabled());
        presenter.checkbox.setValue(true);
        presenter.checkboxOrTextboxChange(presenter.checkbox);
        Assert.assertEquals(true, presenter.data.isEnabled());
    }

    @Test
    public void testClickBox() {
        Assert.assertEquals("red", presenter.data.getColor());
        presenter.color.setBackgroundColor("red");
        presenter.color$click();
        Assert.assertEquals("blue", presenter.data.getColor());
        presenter.color.setBackgroundColor("blue");
        presenter.color$click();
        Assert.assertEquals("red", presenter.data.getColor());
    }

    @Test
    public void testTextbox() {
        Assert.assertEquals("Hello", presenter.data.getText());
        String goodbye = "Goodbye";
        presenter.textbox.setText(goodbye);
        presenter.checkboxOrTextboxChange(presenter.textbox);
        Assert.assertEquals(goodbye, presenter.data.getText());
        String guitRocks = "Guit Rocks!";
        presenter.textbox.setText(guitRocks);
        presenter.checkboxOrTextboxChange(presenter.textbox);
        Assert.assertEquals(guitRocks, presenter.data.getText());
    }
}
